#!/bin/bash

# ============================================
# 深度排查 Nginx 配置问题
# ============================================

echo "=== 检查 Nginx 主配置文件 ==="
cat /etc/nginx/nginx.conf | grep -A 20 "http {" | tail -25

echo ""
echo "=== 检查所有 server 块 ==="
sudo nginx -T 2>/dev/null | grep -B 3 -A 5 "listen 80"

echo ""
echo "=== 检查是否有默认 server 块 ==="
sudo nginx -T 2>/dev/null | grep -B 10 -A 15 "default_server\|server_name _"

echo ""
echo "=== 检查 frontend.conf 是否被包含 ==="
grep -r "include.*conf.d" /etc/nginx/nginx.conf

echo ""
echo "=== 查看当前 frontend.conf 内容 ==="
cat /etc/nginx/conf.d/frontend.conf | head -30

echo ""
echo "=== 检查 Nginx 实际加载的配置 ==="
sudo nginx -T 2>/dev/null | grep -A 30 "location /api/" | head -35

echo ""
echo "=== 测试并查看详细日志 ==="
curl -s http://127.0.0.1/api/login/ > /dev/null
echo "访问日志："
sudo tail -2 /var/log/nginx/frontend_access.log 2>/dev/null || echo "无访问日志"
echo "错误日志："
sudo tail -5 /var/log/nginx/frontend_error.log 2>/dev/null || echo "无错误日志"

